package application;

import java.util.ArrayList;

import database.Database;

import entreprise.Category;
import entreprise.Client;
import entreprise.Email;
import entreprise.Food;
import entreprise.Reservation;

public class RestoService {
	Database database;

	public RestoService() {
		super();
		database = new Database("restoreservation");
	}

	public boolean addClient(String name_client, String user_id, String passwd,
			String birthday, String numberphone, String email) {
		boolean res = true;
		try {
			Client client = new Client(name_client, user_id, passwd, birthday,
					numberphone, email);
			client.setDatabase(database);
			res = client.addClient();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean addCategory(String name_category) {
		boolean res = true;
		try {
			Category category = new Category(name_category);
			category.setDatabase(database);
			res = category.addCategory();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean addFood(String id_category, String name_food,
			String description, String country, String image, String price) {
		boolean res = true;
		try {
			Food food = new Food(id_category, name_food, description, country,
					image, price);
			food.setDatabase(database);
			res = food.addFood();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean addReservation(String id_food, String id_client,
			String amount, String date_eat, String time_eat) {
		boolean res = true;
		try {
			Reservation reservation = new Reservation(id_food, id_client,
					amount, date_eat, time_eat);
			reservation.setDatabase(database);
			res = reservation.addReservation();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean updateCategory(String id_category, String name_category) {
		boolean res = true;
		Category category = new Category(id_category, name_category);
		category.setDatabase(database);
		try {
			res = category.updateCategory();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean updateFood(String id_food, String id_category,
			String name_food, String description, String country, String image,
			String price) {
		boolean res = true;
		try {
			Food food = new Food(id_food, id_category, name_food, description,
					country, image, price);
			food.setDatabase(database);
			res = food.updateFood();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean updateReservation(String id_food, String id_client,
			String amount, String time_reservation, String time_eat) {
		boolean res = true;
		try {
			Reservation reservation = new Reservation(id_food, id_client,
					amount, time_reservation, time_eat);
			reservation.setDatabase(database);
			res = reservation.updateReservation();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean deleteCategory(String id_category) {
		boolean res = true;
		Category category = new Category(id_category, "");
		category.setDatabase(database);
		try {
			res = category.deleteCategory();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean deleteFood(String id_food) {
		boolean res = true;
		Food food = new Food(id_food);
		food.setDatabase(database);
		try {
			res = food.deleteFood();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public boolean deleteReservation(String id_reservation) {
		boolean res = true;
		Reservation reservation = new Reservation(id_reservation);
		reservation.setDatabase(database);
		try {
			res = reservation.deleteReservation();
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return res;
	}

	public ArrayList<ArrayList<String>> listAllClient() {
		Client client = new Client();
		client.setDatabase(database);
		return client.getAllClient();
	}

	public ArrayList<String> listClientWithID(String id_client) {
		Client client = new Client();
		client.setDatabase(database);
		return client.listClientWithId(id_client);
	}

	public ArrayList<String> listClientWithUserIdPasswd(String user_id,
			String passwd) {
		Client client = new Client();
		client.setDatabase(database);
		return client.listClientWithUserIdPasswd(user_id, passwd);
	}

	public ArrayList<String> listClientWithUserID(String user_id) {
		Client client = new Client();
		client.setDatabase(database);
		return client.listClientWithUserID(user_id);
	}

	public ArrayList<ArrayList<String>> listAllCategory() {
		Category category = new Category();
		category.setDatabase(database);
		return category.listAllCategory();
	}

	public ArrayList<String> listCategoryWithName(String category_name) {
		Category category = new Category();
		category.setDatabase(database);
		return category.listCategoryWithName(category_name);
	}

	public ArrayList<ArrayList<String>> listAllFood() {
		Food food = new Food();
		food.setDatabase(database);
		return food.listAllFood();
	}
	
	public ArrayList<ArrayList<String>> listFoodWithCategory(String id_category) {
		Food food = new Food();
		food.setDatabase(database);
		return food.listFoodWithCategory(id_category);
	}

	public ArrayList<String> listFoodWithID(String id_food) {
		Food food = new Food();
		food.setDatabase(database);
		return food.listFoodWithID(id_food);
	}

	public ArrayList<ArrayList<String>> listAllReservation() {
		Reservation reservation = new Reservation();
		reservation.setDatabase(database);
		return reservation.listAllReservation();
	}

	public ArrayList<String> listReservationWithID(String id_reservation) {
		Reservation reservation = new Reservation();
		reservation.setDatabase(database);
		return reservation.listReservationWithID(id_reservation);
	}

	public ArrayList<ArrayList<String>> listReservationWithIdClient(
			String id_client) {
		Reservation reservation = new Reservation();
		reservation.setDatabase(database);
		return reservation.listReservationWithIdClient(id_client);
	}

	public ArrayList<ArrayList<String>> listClientReserve() {
		Reservation reservation = new Reservation();
		reservation.setDatabase(database);
		return reservation.listClientReserve();
	}

	public ArrayList<ArrayList<String>> listReservation(String id_client,
			String date_eat, String time_eat) {
		Reservation reservation = new Reservation();
		reservation.setDatabase(database);
		return reservation.listReservation(id_client, date_eat, time_eat);
	}

	public boolean sendMail(String from, String to, String subject,
			String content) {
		Email mail = new Email();
		mail.setUser_name_recive(to);
		mail.setUser_name_send(from);
		mail.setSubject(subject);
		mail.setContent(content);
		return mail.sendMail();
	}

	public String getEmailClient(String id_client) {
		Client client = new Client();
		client.setDatabase(database);
		return client.getEmail(id_client);
	}

}
